package com.inei.cie.dao;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.inei.cie.entidades.P5_N;
import com.inei.cie.entidades.P6_1;
import com.inei.cie.entidades.P6_1_10N;
import com.inei.cie.entidades.P6_1_8N;
import com.inei.cie.entidades.P6_2;
import com.inei.cie.entidades.P6_2_4N;
import com.inei.cie.entidades.P7;

public class CapituloVIIDao {

	private UtilDB util;
	SQLiteDatabase db;
	Cursor cursor = null;

	public CapituloVIIDao(Context context) {
		util = new UtilDB(context);
	}

	public int totalEdificaciones(String id_local, int Nro_Pred) {
		int nroEdificaciones = 0;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P5 where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			while (!cursor.isAfterLast()) {
				nroEdificaciones = cursor.getInt(cursor
						.getColumnIndex("P5_Tot_E"));
				cursor.moveToNext();
			}
			Cerrar();
			return nroEdificaciones;
		} else {
			Cerrar();
			return nroEdificaciones;
		}
	}

	public void crearP7EdificacionesLocal(String id_local, int nro, int Nro_Pred) {
		for (int i = 0; i < nro; i++) {
			if (!existeP7Local(id_local, Nro_Pred, (i + 1))) {
				db = util.getWritableDatabase();
				ContentValues c = new ContentValues();
				c.put("id_local", id_local);
				c.put("Nro_Pred", Nro_Pred);
				c.put("Nro_Ed", (i + 1));
				db.insert("P7", null, c);
				db.close();
			}
		}
	}

	public boolean existeP7Local(String id_local, int Nro_Pred, int Nro_Ed) {
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P7 where id_local=? and Nro_Pred=? and Nro_Ed=?",
						new String[] { id_local + "", Nro_Pred + "",
								Nro_Ed + "" });
		if (cursor.moveToFirst()) {
			Cerrar();
			return true;
		} else {
			Cerrar();
			return false;
		}
	}

	public P7 obtenerP7Edificacion(String id_local, int Nro_Ed, int Nro_Pred) {
		P7 obj = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"SELECT * FROM P7 WHERE id_local=? AND Nro_Ed=? and Nro_Pred=?",
						new String[] { id_local + "", Nro_Ed + "",
								Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			while (!cursor.isAfterLast()) {
				obj = new P7();
				obj.setId_local(id_local);
				obj.setNro_Ed(Nro_Ed);
				obj.setNro_Pred(Nro_Pred);
				obj.setP7_1_2(cursor.getInt(cursor.getColumnIndex("P7_1_2")));
				obj.setP7_1_3(cursor.getInt(cursor.getColumnIndex("P7_1_3")));
				obj.setP7_1_4(cursor.getInt(cursor.getColumnIndex("P7_1_4")));
				obj.setP7_1_5(cursor.getInt(cursor.getColumnIndex("P7_1_5")));
				obj.setP7_1_6(cursor.getInt(cursor.getColumnIndex("P7_1_6")));
				obj.setP7_1_7(cursor.getInt(cursor.getColumnIndex("P7_1_7")));
				obj.setP7_1_8(cursor.getInt(cursor.getColumnIndex("P7_1_8")));
				obj.setP7_1_9(cursor.getInt(cursor.getColumnIndex("P7_1_9")));
				obj.setP7_1_9A(cursor.getInt(cursor.getColumnIndex("P7_1_9A")));
				obj.setP7_1_9B(cursor.getInt(cursor.getColumnIndex("P7_1_9B")));
				obj.setP7_1_9C(cursor.getInt(cursor.getColumnIndex("P7_1_9C")));
				obj.setP7_1_9D(cursor.getInt(cursor.getColumnIndex("P7_1_9D")));
				obj.setP7_1_10(cursor.getInt(cursor.getColumnIndex("P7_1_10")));
				obj.setP7_1_11(cursor.getInt(cursor.getColumnIndex("P7_1_11")));
				obj.setP7_1_12(cursor.getInt(cursor.getColumnIndex("P7_1_12")));
				obj.setP7_1_13(cursor.getInt(cursor.getColumnIndex("P7_1_13")));
				obj.setP7_1_14(cursor.getInt(cursor.getColumnIndex("P7_1_14")));
				obj.setP7_1_15(cursor.getInt(cursor.getColumnIndex("P7_1_15")));
				obj.setP7_1_15A(cursor.getInt(cursor.getColumnIndex("P7_1_15A")));
				obj.setP7_1_15B(cursor.getInt(cursor.getColumnIndex("P7_1_15B")));
				obj.setP7_1_15C(cursor.getInt(cursor.getColumnIndex("P7_1_15C")));
				obj.setP7_1_15D(cursor.getInt(cursor.getColumnIndex("P7_1_15D")));
				obj.setP7_1_16(cursor.getInt(cursor.getColumnIndex("P7_1_16")));
				obj.setP7_1_17(cursor.getInt(cursor.getColumnIndex("P7_1_17")));
				obj.setP7_1_18(cursor.getInt(cursor.getColumnIndex("P7_1_18")));
				obj.setP7_1_19(cursor.getInt(cursor.getColumnIndex("P7_1_19")));
				obj.setP7_1_20(cursor.getInt(cursor.getColumnIndex("P7_1_20")));
				obj.setP7_1_21(cursor.getInt(cursor.getColumnIndex("P7_1_21")));
				obj.setP7_1_22(cursor.getInt(cursor.getColumnIndex("P7_1_22")));
				obj.setP7_1_23(cursor.getInt(cursor.getColumnIndex("P7_1_23")));
				obj.setP7_1_24(cursor.getInt(cursor.getColumnIndex("P7_1_24")));
				obj.setP7_1_25(cursor.getInt(cursor.getColumnIndex("P7_1_25")));
				obj.setP7_1_26(cursor.getInt(cursor.getColumnIndex("P7_1_26")));
				obj.setP7_1_27(cursor.getInt(cursor.getColumnIndex("P7_1_27")));
				obj.setP7_1_28(cursor.getInt(cursor.getColumnIndex("P7_1_28")));
				obj.setP7_2_1(cursor.getInt(cursor.getColumnIndex("P7_2_1")));
				obj.setP7_2_2(cursor.getString(cursor.getColumnIndex("P7_2_2")));
				// obj.setP7_OBS(cursor.getString(cursor.getColumnIndex("P7_OBS")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				cursor.moveToNext();
			}
		}
		Cerrar();
		return obj;
	}

	public void actualizarP7Edificacion(P7 obj) {
		db = util.getWritableDatabase();
		ContentValues valores = new ContentValues();
		valores.put("P7_1_2", obj.getP7_1_2());
		valores.put("P7_1_3", obj.getP7_1_3());
		valores.put("P7_1_4", obj.getP7_1_4());
		valores.put("P7_1_5", obj.getP7_1_5());
		valores.put("P7_1_6", obj.getP7_1_6());
		valores.put("P7_1_7", obj.getP7_1_7());
		valores.put("P7_1_8", obj.getP7_1_8());
		valores.put("P7_1_9", obj.getP7_1_9());
		valores.put("P7_1_9A", obj.getP7_1_9A());
		valores.put("P7_1_9B", obj.getP7_1_9B());
		valores.put("P7_1_9C", obj.getP7_1_9C());
		valores.put("P7_1_9D", obj.getP7_1_9D());
		valores.put("P7_1_10", obj.getP7_1_10());
		valores.put("P7_1_11", obj.getP7_1_11());
		valores.put("P7_1_12", obj.getP7_1_12());
		valores.put("P7_1_13", obj.getP7_1_13());
		valores.put("P7_1_14", obj.getP7_1_14());
		valores.put("P7_1_15", obj.getP7_1_15());
		valores.put("P7_1_15A", obj.getP7_1_15A());
		valores.put("P7_1_15B", obj.getP7_1_15B());
		valores.put("P7_1_15C", obj.getP7_1_15C());
		valores.put("P7_1_15D", obj.getP7_1_15D());
		valores.put("P7_1_16", obj.getP7_1_16());
		valores.put("P7_1_17", obj.getP7_1_17());
		valores.put("P7_1_18", obj.getP7_1_18());
		valores.put("P7_1_19", obj.getP7_1_19());
		valores.put("P7_1_20", obj.getP7_1_20());
		valores.put("P7_1_21", obj.getP7_1_21());
		valores.put("P7_1_22", obj.getP7_1_22());
		valores.put("P7_1_23", obj.getP7_1_23());
		valores.put("P7_1_24", obj.getP7_1_24());
		valores.put("P7_1_25", obj.getP7_1_25());
		valores.put("P7_1_26", obj.getP7_1_26());
		valores.put("P7_1_27", obj.getP7_1_27());
		valores.put("P7_1_28", obj.getP7_1_28());
		valores.put("P7_2_1", obj.getP7_2_1());
		valores.put("P7_2_2", obj.getP7_2_2());
		// valores.put("P7_OBS", obj.getP7_OBS());
		valores.put("Version", obj.getVersion());
		valores.put("SwCompleto", obj.isSwCompleto());
		valores.put("SwEnviado", obj.isSwEnviado());

		int ind = db.update("P7", valores,
				"id_local=? and Nro_Ed=? and Nro_Pred=?",
				new String[] { obj.getId_local() + "", obj.getNro_Ed() + "",
						obj.getNro_Pred() + "" });
		Cerrar();
	}

	public void eliminarEdificacion(String id_local, int Nro_Pred,
			int edificacion) {
		int total = 0;

		db = util.getWritableDatabase();
		db.delete("P5_N", "id_local=? and Nro_Pred=? and P5_Ed_Nro=?",
				new String[] { id_local + "", Nro_Pred + "", edificacion + "" });
		db.close();
		List<P5_N> listaP5 = obtenerEdificacionesP5_N(id_local, Nro_Pred);

		db = util.getWritableDatabase();
		db.delete("P7", "id_local=? and Nro_Pred=? and Nro_Ed=?", new String[] {
				id_local + "", Nro_Pred + "", edificacion + "" });
		db.close();
		List<P7> listaP7 = obtenerEdificacionesP7(id_local, Nro_Pred);

		db = util.getWritableDatabase();
		db.delete("P6_1", "id_local=? and Nro_Pred=? and Nro_Ed=?",
				new String[] { id_local + "", Nro_Pred + "", edificacion + "" });
		db.close();
		List<P6_1> listaP6_1 = obtenerEdificacionesP6_1(id_local, Nro_Pred);

		db = util.getWritableDatabase();
		db.delete("P6_1_8N", "id_local=? and Nro_Pred=? and Nro_Ed=?",
				new String[] { id_local + "", Nro_Pred + "", edificacion + "" });
		db.close();
		List<P6_1_8N> listaP6_1_8 = obtenerEdificacionesP6_1_8N(id_local,
				Nro_Pred);

		db = util.getWritableDatabase();
		db.delete("P6_1_10N", "id_local=? and Nro_Pred=? and Nro_Ed=?",
				new String[] { id_local + "", Nro_Pred + "", edificacion + "" });
		db.close();
		List<P6_1_10N> listaP6_1_10 = obtenerEdificacionesP6_1_10N(id_local,
				Nro_Pred);

		db = util.getWritableDatabase();
		db.delete("P6_2", "id_local=? and Nro_Pred=? and Nro_Ed=?",
				new String[] { id_local + "", Nro_Pred + "", edificacion + "" });
		db.close();
		List<P6_2> listaP6_2 = obtenerEdificacionesP6_2(id_local, Nro_Pred);

		db = util.getWritableDatabase();
		db.delete("P6_2_4N", "id_local=? and Nro_Pred=? and Nro_Ed=?",
				new String[] { id_local + "", Nro_Pred + "", edificacion + "" });
		db.close();
		List<P6_2_4N> listaP6_2_4 = obtenerEdificacionesP6_2_4N(id_local,
				Nro_Pred);

		if (listaP5 != null) {
			// P5_N
			for (int i = edificacion; i <= listaP5.size(); i++) {
				db = util.getWritableDatabase();
				ContentValues c = new ContentValues();
				c.put("P5_Ed_Nro", i);
				db.update("P5_N", c,
						"id_local=? and Nro_Pred=? and P5_Ed_Nro=?",
						new String[] { id_local + "", Nro_Pred + "",
								(i + 1) + "" });
				db.close();
			}
		}

		if (listaP7 != null) {
			// P7
			if (listaP7 != null) {
				for (int i = edificacion; i <= listaP7.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("Nro_Ed", i);
					db.update("P7", c,
							"id_local=? and Nro_Pred=? and Nro_Ed=?",
							new String[] { id_local + "", Nro_Pred + "",
									(i + 1) + "" });
					db.close();
				}
			}
			// P6_1
			if (listaP6_1 != null) {
				for (int i = edificacion; i <= listaP6_1.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("Nro_Ed", i);
					db.update("P6_1", c,
							"id_local=? and Nro_Pred=? and Nro_Ed=?",
							new String[] { id_local + "", Nro_Pred + "",
									(i + 1) + "" });
					db.close();
				}
			}
			// P6_1_8N
			if (listaP6_1_8 != null) {
				for (int i = edificacion; i <= listaP6_1_8.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("Nro_Ed", i);
					db.update("P6_1_8N", c,
							"id_local=? and Nro_Pred=? and Nro_Ed=?",
							new String[] { id_local + "", Nro_Pred + "",
									(i + 1) + "" });
					db.close();
				}
			}
			// P6_1_10N
			if (listaP6_1_10 != null) {
				for (int i = edificacion; i <= listaP6_1_10.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("Nro_Ed", i);
					db.update("P6_1_10N", c,
							"id_local=? and Nro_Pred=? and Nro_Ed=?",
							new String[] { id_local + "", Nro_Pred + "",
									(i + 1) + "" });
					db.close();
				}
			}
			// P6_2
			if (listaP6_2 != null) {
				for (int i = edificacion; i <= listaP6_2.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("Nro_Ed", i);
					db.update("P6_2", c,
							"id_local=? and Nro_Pred=? and Nro_Ed=?",
							new String[] { id_local + "", Nro_Pred + "",
									(i + 1) + "" });
					db.close();
				}
			}
			// P6_2_4N
			if (listaP6_2_4 != null) {
				for (int i = edificacion; i <= listaP6_2_4.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("Nro_Ed", i);
					db.update("P6_2_4N", c,
							"id_local=? and Nro_Pred=? and Nro_Ed=?",
							new String[] { id_local + "", Nro_Pred + "",
									(i + 1) + "" });
					db.close();
				}
			}
		}

		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P7 where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			total = cursor.getCount();
		}
		db.close();
		db = util.getWritableDatabase();
		ContentValues c = new ContentValues();
		c.put("P5_Tot_E", total);
		db.update("P5", c, "id_local=? and Nro_Pred=?", new String[] {
				id_local + "", Nro_Pred + "" });
		Cerrar();
	}

	public List<P5_N> obtenerEdificacionesP5_N(String id_local, int Nro_Pred) {
		List<P5_N> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P5_N where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P5_N>();
			while (!cursor.isAfterLast()) {
				P5_N obj = new P5_N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setP5_NroPiso(cursor.getInt(cursor
						.getColumnIndex("P5_NroPiso")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setP5_Ed_Nro(cursor.getInt(cursor
						.getColumnIndex("P5_Ed_Nro")));
				obj.setP5_TotAmb(cursor.getInt(cursor
						.getColumnIndex("P5_TotAmb")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P7> obtenerEdificacionesP7(String id_local, int Nro_Pred) {
		List<P7> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P7 where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P7>();
			while (!cursor.isAfterLast()) {
				P7 obj = new P7();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj.setP7_1_2(cursor.getInt(cursor.getColumnIndex("P7_1_2")));
				obj.setP7_1_3(cursor.getInt(cursor.getColumnIndex("P7_1_3")));
				obj.setP7_1_4(cursor.getInt(cursor.getColumnIndex("P7_1_4")));
				obj.setP7_1_5(cursor.getInt(cursor.getColumnIndex("P7_1_5")));
				obj.setP7_1_6(cursor.getInt(cursor.getColumnIndex("P7_1_6")));
				obj.setP7_1_7(cursor.getInt(cursor.getColumnIndex("P7_1_7")));
				obj.setP7_1_8(cursor.getInt(cursor.getColumnIndex("P7_1_8")));
				obj.setP7_1_9(cursor.getInt(cursor.getColumnIndex("P7_1_9")));
				obj.setP7_1_9A(cursor.getInt(cursor.getColumnIndex("P7_1_9A")));
				obj.setP7_1_9B(cursor.getInt(cursor.getColumnIndex("P7_1_9B")));
				obj.setP7_1_9C(cursor.getInt(cursor.getColumnIndex("P7_1_9C")));
				obj.setP7_1_9D(cursor.getInt(cursor.getColumnIndex("P7_1_9D")));
				obj.setP7_1_10(cursor.getInt(cursor.getColumnIndex("P7_1_10")));
				obj.setP7_1_11(cursor.getInt(cursor.getColumnIndex("P7_1_11")));
				obj.setP7_1_12(cursor.getInt(cursor.getColumnIndex("P7_1_12")));
				obj.setP7_1_13(cursor.getInt(cursor.getColumnIndex("P7_1_13")));
				obj.setP7_1_14(cursor.getInt(cursor.getColumnIndex("P7_1_14")));
				obj.setP7_1_15(cursor.getInt(cursor.getColumnIndex("P7_1_15")));
				obj.setP7_1_15A(cursor.getInt(cursor.getColumnIndex("P7_1_15A")));
				obj.setP7_1_15B(cursor.getInt(cursor.getColumnIndex("P7_1_15B")));
				obj.setP7_1_15C(cursor.getInt(cursor.getColumnIndex("P7_1_15C")));
				obj.setP7_1_15D(cursor.getInt(cursor.getColumnIndex("P7_1_15D")));
				obj.setP7_1_16(cursor.getInt(cursor.getColumnIndex("P7_1_16")));
				obj.setP7_1_17(cursor.getInt(cursor.getColumnIndex("P7_1_17")));
				obj.setP7_1_18(cursor.getInt(cursor.getColumnIndex("P7_1_18")));
				obj.setP7_1_19(cursor.getInt(cursor.getColumnIndex("P7_1_19")));
				obj.setP7_1_20(cursor.getInt(cursor.getColumnIndex("P7_1_20")));
				obj.setP7_1_21(cursor.getInt(cursor.getColumnIndex("P7_1_21")));
				obj.setP7_1_22(cursor.getInt(cursor.getColumnIndex("P7_1_22")));
				obj.setP7_1_23(cursor.getInt(cursor.getColumnIndex("P7_1_23")));
				obj.setP7_1_24(cursor.getInt(cursor.getColumnIndex("P7_1_24")));
				obj.setP7_1_25(cursor.getInt(cursor.getColumnIndex("P7_1_25")));
				obj.setP7_1_26(cursor.getInt(cursor.getColumnIndex("P7_1_26")));
				obj.setP7_1_27(cursor.getInt(cursor.getColumnIndex("P7_1_27")));
				obj.setP7_1_28(cursor.getInt(cursor.getColumnIndex("P7_1_28")));
				obj.setP7_2_1(cursor.getInt(cursor.getColumnIndex("P7_2_1")));
				obj.setP7_2_2(cursor.getString(cursor.getColumnIndex("P7_2_2")));
				// obj.setP7_OBS(cursor.getString(cursor.getColumnIndex("P7_OBS")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P6_1> obtenerEdificacionesP6_1(String id_local, int Nro_Pred) {
		List<P6_1> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P6_1 where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P6_1>();
			while (!cursor.isAfterLast()) {
				P6_1 obj = new P6_1();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj.setP6_1_3(cursor.getFloat(cursor.getColumnIndex("P6_1_3")));
				obj.setP6_1_4(cursor.getInt(cursor.getColumnIndex("P6_1_4")));
				obj.setP6_1_5(cursor.getInt(cursor.getColumnIndex("P6_1_5")));
				obj.setP6_1_6(cursor.getInt(cursor.getColumnIndex("P6_1_6")));
				obj.setP6_1_7(cursor.getInt(cursor.getColumnIndex("P6_1_7")));
				obj.setP6_1_8(cursor.getInt(cursor.getColumnIndex("P6_1_8")));
				obj.setP6_1_9(cursor.getInt(cursor.getColumnIndex("P6_1_9")));
				obj.setP6_3_1(cursor.getInt(cursor.getColumnIndex("P6_3_1")));
				obj.setP6_3_1A(cursor.getInt(cursor.getColumnIndex("P6_3_1A")));
				obj.setP6_3_2(cursor.getInt(cursor.getColumnIndex("P6_3_2")));
				obj.setP6_3_2A(cursor.getInt(cursor.getColumnIndex("P6_3_2A")));
				obj.setP6_3_2B(cursor.getInt(cursor.getColumnIndex("P6_3_2B")));
				obj.setP6_3_2C(cursor.getInt(cursor.getColumnIndex("P6_3_2C")));
				obj.setP6_3_2D(cursor.getInt(cursor.getColumnIndex("P6_3_2D")));
				obj.setP6_3_3(cursor.getInt(cursor.getColumnIndex("P6_3_3")));
				obj.setP6_3_3A(cursor.getInt(cursor.getColumnIndex("P6_3_3A")));
				obj.setP6_4_1(cursor.getInt(cursor.getColumnIndex("P6_4_1")));
				obj.setP6_4_1A(cursor.getInt(cursor.getColumnIndex("P6_4_1A")));
				obj.setP6_4_2(cursor.getInt(cursor.getColumnIndex("P6_4_2")));
				obj.setP6_5_1(cursor.getInt(cursor.getColumnIndex("P6_5_1")));
				obj.setP6_5_1A(cursor.getInt(cursor.getColumnIndex("P6_5_1A")));
				obj.setP6_5_2(cursor.getInt(cursor.getColumnIndex("P6_5_2")));
				obj.setP6_OBS(cursor.getString(cursor.getColumnIndex("P6_OBS")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P6_1_8N> obtenerEdificacionesP6_1_8N(String id_local,
			int Nro_Pred) {
		List<P6_1_8N> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P6_1_8N where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P6_1_8N>();
			while (!cursor.isAfterLast()) {
				P6_1_8N obj = new P6_1_8N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setP6_1_8ID(cursor.getInt(cursor.getColumnIndex("P6_1_8ID")));
				obj.setP6_1_8_ACCESIBILIDAD(cursor.getInt(cursor
						.getColumnIndex("P6_1_8_ACCESIBILIDAD")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P6_1_10N> obtenerEdificacionesP6_1_10N(String id_local,
			int Nro_Pred) {
		List<P6_1_10N> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P6_1_10N where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P6_1_10N>();
			while (!cursor.isAfterLast()) {
				P6_1_10N obj = new P6_1_10N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setP6_1_10(cursor.getInt(cursor.getColumnIndex("P6_1_10")));
				obj.setP6_1_10_e(cursor.getInt(cursor
						.getColumnIndex("P6_1_10_e")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P6_2> obtenerEdificacionesP6_2(String id_local, int Nro_Pred) {
		List<P6_2> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P6_2 where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P6_2>();
			while (!cursor.isAfterLast()) {
				P6_2 obj = new P6_2();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj.setP6_2_1(cursor.getInt(cursor.getColumnIndex("P6_2_1")));
				obj.setP6_2_2(cursor.getInt(cursor.getColumnIndex("P6_2_2")));
				obj.setP6_2_3(cursor.getInt(cursor.getColumnIndex("P6_2_3")));
				obj.setP6_2_5(cursor.getInt(cursor.getColumnIndex("P6_2_5")));
				obj.setP6_2_6(cursor.getInt(cursor.getColumnIndex("P6_2_6")));
				obj.setP6_2_7(cursor.getInt(cursor.getColumnIndex("P6_2_7")));
				obj.setP6_2_7_O(cursor.getString(cursor
						.getColumnIndex("P6_2_7_O")));
				obj.setP6_2_8(cursor.getInt(cursor.getColumnIndex("P6_2_8")));
				obj.setP6_2_8_O(cursor.getString(cursor
						.getColumnIndex("P6_2_8_O")));
				obj.setP6_2_9(cursor.getInt(cursor.getColumnIndex("P6_2_9")));
				obj.setP6_2_9_O(cursor.getString(cursor
						.getColumnIndex("P6_2_9_O")));
				obj.setP6_2_10(cursor.getInt(cursor.getColumnIndex("P6_2_10")));
				obj.setP6_2_10_O(cursor.getString(cursor
						.getColumnIndex("P6_2_10_O")));
				obj.setP6_2_11(cursor.getInt(cursor.getColumnIndex("P6_2_11")));
				obj.setP6_2_11_O(cursor.getString(cursor
						.getColumnIndex("P6_2_11_O")));
				obj.setP6_2_12(cursor.getInt(cursor.getColumnIndex("P6_2_12")));
				obj.setP6_2_12_O(cursor.getString(cursor
						.getColumnIndex("P6_2_12_O")));
				obj.setP6_2_13(cursor.getInt(cursor.getColumnIndex("P6_2_13")));
				obj.setP6_2_13_O(cursor.getString(cursor
						.getColumnIndex("P6_2_13_O")));
				obj.setP6_2_14_1(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_1")));
				obj.setP6_2_14_2(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_2")));
				obj.setP6_2_14_3(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_3")));
				obj.setP6_2_14_4(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_4")));
				obj.setP6_2_14_5(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_5")));
				obj.setP6_2_14_6(cursor.getInt(cursor
						.getColumnIndex("P6_2_14_6")));
				obj.setP6_2_14a(cursor.getInt(cursor.getColumnIndex("P6_2_14a")));
				obj.setP6_2_14b_1(cursor.getInt(cursor
						.getColumnIndex("P6_2_14b_1")));
				obj.setP6_2_14b_2(cursor.getInt(cursor
						.getColumnIndex("P6_2_14b_2")));
				obj.setP6_2_15(cursor.getInt(cursor.getColumnIndex("P6_2_15")));
				obj.setP6_2_15_O(cursor.getString(cursor
						.getColumnIndex("P6_2_15_O")));
				obj.setP6_2_15a(cursor.getInt(cursor.getColumnIndex("P6_2_15a")));
				obj.setP6_2_16a(cursor.getInt(cursor.getColumnIndex("P6_2_16a")));
				obj.setP6_2_16a_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_16a_b")));
				obj.setP6_2_16a_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_16a_r")));
				obj.setP6_2_16a_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_16a_m")));
				obj.setP6_2_16b(cursor.getInt(cursor.getColumnIndex("P6_2_16b")));
				obj.setP6_2_16b_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_16b_b")));
				obj.setP6_2_16b_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_16b_r")));
				obj.setP6_2_16b_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_16b_m")));
				obj.setP6_2_16c(cursor.getInt(cursor.getColumnIndex("P6_2_16c")));
				obj.setP6_2_16c_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_16c_b")));
				obj.setP6_2_16c_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_16c_r")));
				obj.setP6_2_16c_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_16c_m")));
				obj.setP6_2_16d(cursor.getInt(cursor.getColumnIndex("P6_2_16d")));
				obj.setP6_2_16d_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_16d_b")));
				obj.setP6_2_16d_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_16d_r")));
				obj.setP6_2_16d_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_16d_m")));
				obj.setP6_2_16e(cursor.getInt(cursor.getColumnIndex("P6_2_16e")));
				obj.setP6_2_16e_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_16e_b")));
				obj.setP6_2_16e_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_16e_r")));
				obj.setP6_2_16e_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_16e_m")));
				obj.setP6_2_16e_O(cursor.getString(cursor
						.getColumnIndex("P6_2_16e_O")));
				obj.setP6_2_16f(cursor.getInt(cursor.getColumnIndex("P6_2_16f")));
				obj.setP6_2_17a(cursor.getInt(cursor.getColumnIndex("P6_2_17a")));
				obj.setP6_2_17b(cursor.getInt(cursor.getColumnIndex("P6_2_17b")));
				obj.setP6_2_17c(cursor.getInt(cursor.getColumnIndex("P6_2_17c")));
				obj.setP6_2_17d(cursor.getInt(cursor.getColumnIndex("P6_2_17d")));
				obj.setP6_2_18a(cursor.getInt(cursor.getColumnIndex("P6_2_18a")));
				obj.setP6_2_18a_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_18a_b")));
				obj.setP6_2_18a_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_18a_r")));
				obj.setP6_2_18a_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_18a_m")));
				obj.setP6_2_18b(cursor.getInt(cursor.getColumnIndex("P6_2_18b")));
				obj.setP6_2_18b_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_18b_b")));
				obj.setP6_2_18b_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_18b_r")));
				obj.setP6_2_18b_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_18b_m")));
				obj.setP6_2_18c(cursor.getInt(cursor.getColumnIndex("P6_2_18c")));
				obj.setP6_2_18c_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_18c_b")));
				obj.setP6_2_18c_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_18c_r")));
				obj.setP6_2_18c_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_18c_m")));
				obj.setP6_2_18d(cursor.getInt(cursor.getColumnIndex("P6_2_18d")));
				obj.setP6_2_18d_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_18d_b")));
				obj.setP6_2_18d_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_18d_r")));
				obj.setP6_2_18d_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_18d_m")));
				obj.setP6_2_18e(cursor.getInt(cursor.getColumnIndex("P6_2_18e")));
				obj.setP6_2_18e_b(cursor.getInt(cursor
						.getColumnIndex("P6_2_18e_b")));
				obj.setP6_2_18e_r(cursor.getInt(cursor
						.getColumnIndex("P6_2_18e_r")));
				obj.setP6_2_18e_m(cursor.getInt(cursor
						.getColumnIndex("P6_2_18e_m")));
				obj.setP6_2_18e_O(cursor.getString(cursor
						.getColumnIndex("P6_2_18e_O")));
				obj.setP6_2_18f(cursor.getInt(cursor.getColumnIndex("P6_2_18f")));
				obj.setP6_2_19a(cursor.getInt(cursor.getColumnIndex("P6_2_19a")));
				obj.setP6_2_19b(cursor.getInt(cursor.getColumnIndex("P6_2_19b")));
				obj.setP6_2_19c(cursor.getInt(cursor.getColumnIndex("P6_2_19c")));
				obj.setP6_2_20OBS(cursor.getString(cursor
						.getColumnIndex("P6_2_20OBS")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P6_2_4N> obtenerEdificacionesP6_2_4N(String id_local,
			int Nro_Pred) {
		List<P6_2_4N> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P6_2_4N where id_local=? and Nro_Pred=?",
				new String[] { id_local + "", Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P6_2_4N>();
			while (!cursor.isAfterLast()) {
				P6_2_4N obj = new P6_2_4N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setNro_Ed(cursor.getInt(cursor.getColumnIndex("Nro_Ed")));
				obj.setP6_2_1(cursor.getInt(cursor.getColumnIndex("P6_2_1")));
				obj.setP6_2_2(cursor.getInt(cursor.getColumnIndex("P6_2_2")));
				obj.setP6_2_4ID(cursor.getInt(cursor.getColumnIndex("P6_2_4ID")));
				obj.setP6_2_4MOD(cursor.getInt(cursor
						.getColumnIndex("P6_2_4MOD")));
				obj.setP6_2_4TURNO_M(cursor.getInt(cursor
						.getColumnIndex("P6_2_4TURNO_M")));
				obj.setP6_2_4TURNO_T(cursor.getInt(cursor
						.getColumnIndex("P6_2_4TURNO_T")));
				obj.setP6_2_4TURNO_N(cursor.getInt(cursor
						.getColumnIndex("P6_2_4TURNO_N")));
				boolean estado = cursor.getInt(cursor
						.getColumnIndex("SwCompleto")) == 1 ? true : false;
				obj.setSwCompleto(estado);
				boolean enviado = cursor.getInt(cursor
						.getColumnIndex("SwEnviado")) == 1 ? true : false;
				obj.setSwEnviado(enviado);
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	protected void Cerrar() {
		cursor.close();
		db.close();
	}
}
